home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / includes / treeViewClass.php < prev    next >
PHP Script  |  2010-05-19  |  21KB  |  560 lines

  1. <?php
  2. /**
  3.  * Tree View Class
  4.  *
  5.  *
  6.  * PHP version 5
  7.  *
  8.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category   NA
  15.  * @package    NA
  16.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  17.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  18.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19.  * @version    CVS: $Id:$
  20.  * @link       http://www.weezo.net
  21.  * @since      File available since Release 1.0.9
  22.  */
  23.  
  24. /**
  25.  * @desc Generic treeView class
  26.  *
  27.  */
  28. class treeView{
  29.     public    $name; // Tree name/id
  30.     public    $phpTree=false; // Server-side tree
  31.     public    $syncSelectPath=false; // Set to true to use synchronous refreshed treeView / page
  32.     public    $draggableNodes=false; // Set to true to have draggable nodes
  33.     public    $receiverOnlyNodes=false; // Set to true to have receiver-only nodes
  34.     public  $selectFunction=''; // Javascript function called when selecting a node
  35.     public  $toggleFoldFunction=''; // Javascript function called when toggling node folding
  36.     public  $dblClickFunction=''; // Javascript function called when double clicking a node
  37.     public  $rightClickFunction=''; // Javascript function called when right-clicking a node
  38.     public    $sortBy=false; // nodes sort by 'name', 'date' or false (unsorted)
  39.     public    $sortOrder=false; // nodes sort order 'asc' or 'desc')
  40.     public    $sortReset=false; // true to send a reset command to JS class, used to reconstruct tree after a change in sorting
  41.     public    $sync='auto'; // 'sync', 'async', 'auto'
  42.  
  43.     function __construct($name){
  44.         $this->name=$name;
  45.     }
  46.  
  47.     /**
  48.      * @desc Debug
  49.      */
  50.     function __toString(){
  51.         return $this->nodeToString($this->phpTree,0);
  52.     }
  53.  
  54.     private function nodeToString($tree,$level=0){
  55.         $output='';
  56.         foreach ($tree as $key=>$value){
  57.             $output.=str_pad('',$level*3,' ');
  58.             if(!is_array($value)) $output.='['.$key.'] => '.$value."\n";
  59.             else $output.='['.$key.'] => '."\n".$this->nodeToString($value,$level+1);
  60.         }
  61.         return $output;
  62.     }
  63.  
  64.     function save(){cfRSetVar('treeView_'.$this->name,$this);}
  65.  
  66.     /**
  67.      * @desc Update server-side folders tree, and generate JS code needed to update client-side tree
  68.      *
  69.      * PHP Tree structure:
  70.      * 'folder basename'=>Array(
  71.      *             (optional) 'ico'=>icon's name, or '' for standard folder icon,
  72.      *             'sub'=>array of subfolders trees, false if not processed, empty array if no subfolders
  73.      *             (optional) 'path'=>resource base path relative full pathname (only if top element)
  74.      *
  75.      * JS Tree structure:
  76.      * {"folder basename":{
  77.      *         (optional) "ico": icon's name or "" for standard folder icon,
  78.      *         "sub": subfolders tree, false if not processed, {} if no subfolders
  79.      *         },
  80.      * ...
  81.      * }
  82.      *
  83.      * @param string $bottomFolder: selected folder (real path, without *resourceBasePath*)
  84.      * @param boolean $resetTree: true to reset tree and return tree from base folder
  85.      * @return string: JS code or false if $folder not allowed
  86.      */
  87.     function update(){
  88.         return $this->TVArrayToJS($this->phpTree,'');
  89.     }
  90.  
  91.     /**
  92.      * @desc Generate JS formated tree from PHP tree
  93.      *
  94.      * @param array $tree: PHP formated tree
  95.      * @return string: JS formated tree
  96.      */
  97.     public function TVArrayToJS($tree){
  98.         if(!is_array($tree)) return '""';
  99.         $output='{';
  100.         
  101.         if(isset($tree['id'])) $output.='"id":"'.$tree['id'].'",';
  102.         if(isset($tree['label'])) $output.='"label":"'.addslashes($tree['label']).'",';
  103.         if(isset($tree['ico']))   $output.='"ico":"'.$tree['ico'].'",';
  104.         if(isset($tree['path']))  $output.='"path":"'.cfUTF8Encode($tree['path'],false,false).'",';
  105.         if(isset($tree['bottom']))  $output.='"bottom":1,';
  106.         if(isset($tree['tag']))  $output.='"tag":"'.addslashes($tree['tag']).'",';
  107.         if(isset($tree['selected']))  $output.='"selected":1,';
  108.         if(isset($tree['unfolded']))  $output.='"unfolded":1,';
  109.         if(isset($tree['faded']))  $output.='"faded":1,';
  110.         if(isset($tree['disabled']))  $output.='"disabled":1,';
  111.         if(isset($tree['action']))  $output.='"action":"'.addslashes($tree['action']).'",';
  112.  
  113.         $output.='"sub":';
  114.         // Empty tree
  115.         if(!isset($tree['sub']) || !is_array($tree['sub'])) return $output.'false}';
  116.  
  117.         $output.='{';
  118.         $nb=0;
  119.         // Browse subdirs
  120.         foreach ($tree['sub'] as $dir=>$subTree) {
  121.             if($nb>0) $output.=',';
  122.             $output.='"'.cfUTF8Encode($dir,false,false).'":'.$this->TVArrayToJS($subTree);
  123.             $nb++;
  124.         }
  125.         return $output.'}}';
  126.     }
  127.  
  128.     public function node($path){return 'dgi("'.$this->name.'_'.cfResourceRelativePath($path).'")';}
  129.  
  130.     /**
  131.      * @desc Insert Javascript needed for tree view functions
  132.      */
  133.     function commonScripts(){
  134.         if(isset($_ENV[APPLICATION_NAME]['treeViewScriptsSet'])) return ''; else $_ENV[APPLICATION_NAME]['treeViewScriptsSet']=true;
  135.         $output='<script type="text/javascript" language="javascript">';
  136.         $output.="var treeIconPlus=\"".outIconNPNG('treePlus')."\";\n";
  137.         $output.="var treeIconPlusOver=\"".outIconNPNG('treePlusOver','')."\";\n";
  138.         $output.="var treeIconMinus=\"".outIconNPNG('treeMinus')."\";\n";
  139.         $output.="var treeIconMinusOver=\"".outIconNPNG('treeMinusOver','')."\";\n";
  140.         $output.="var treeIconLoading=\"".outIconNPNG('treeLoading')."\";\n";
  141.         $output.="var treeIconError=\"".outIconNPNG('treeError')."\";\n";
  142.         $output.="var treeIconFolder=\"".outIconNPNG('fi/folder')."\";\n";
  143.         $output.="var treeIconFolderO=\"".outIconNPNG('fi/folderO')."\";\n";
  144.         $output.="var treeUnfoldOnSelect=".((cfBGetVar('screenSize')=='monitor')?0:1).";\n";
  145.         $output.="var treeOpenTimeout=".(cfHGetVar('treeOpenTimeout',1000)).";\n";
  146.         return $output."</script>\n".cfScriptLink('treeView.js');
  147.     }
  148.  
  149.     /**
  150.      * @desc Set whole tree data on synchronous refresh
  151.      *
  152.      * @param string $tv: JS tree definition
  153.      */
  154.     function createTreeView(){
  155.         $output = '<script type="text/javascript">';
  156.         $output .= 'treeViews["'.$this->name.'"]=new treeView("'.$this->name.'",'.$this->update(cfRGetVar('efCurrentDirectory'),true,true).');';
  157.         $output.='with(treeViews["'.$this->name.'"]){';
  158.         if($this->syncSelectPath) $output.='setSelectFunction(treeSyncSelectPath);';
  159.         if($this->selectFunction) $output.='setSelectFunction('.$this->selectFunction.');';
  160.         if($this->toggleFoldFunction) $output.='setToggleFoldFunction ('.$this->toggleFoldFunction.');';
  161.         if($this->dblClickFunction) $output.='setDblClickFunction('.$this->dblClickFunction.');';
  162.         if($this->rightClickFunction) $output.='setRightClickFunction('.$this->rightClickFunction.');';
  163.         if($this->draggableNodes) $output .= 'draggableNodes=1;';
  164.         $output.='sync="'.$this->sync.'";';
  165.  
  166.         if($this->receiverOnlyNodes) $output .= 'receiverOnlyNodes=1;';
  167.         $output .= 'init();}';
  168.         return $output.'</script>';
  169.     }
  170.  
  171.     /**
  172.      * @desc Return HTML code for tree view
  173.      *
  174.      * @param string $class: CSS class of outer <div>
  175.      * @param mixed $resizable: false->not resizeable, 'h'->horizontaly resizeable, 'v'->verticaly resizeable
  176.      * @param boolean $closable
  177.      * @param string $extraStyle
  178.      * @param string $extraHTML
  179.      * @param string $header: HTML code of header, leave empty for no header
  180.      * @return string HTML code
  181.      */
  182.     function HTML($class=false, $resizable=false, $closable=false, $extraStyle=false, $extraHTML=false, $header=false){
  183.         // Add common treeView JS
  184.         $output=$this->commonScripts();
  185.  
  186.         // Insert HTML stuff
  187.         $output.='<div id="'.$this->HTMLDivID().'"'.(($class)?' class="'.$class.'"':'').' style="margin:0;overflow:auto;'.$extraStyle.'"'.(($extraHTML)?' '.$extraHTML:'').'>';
  188.  
  189.         if($header){
  190.             if($closable) $output.=outFrameHeaderTable((($class)?$class.'Header':''),$header,outButtonSmall(false,'javascript:treeToggleFrame()',outIcon('close'),cfCaption('genClose')),(($resizable)?' onmouseover="setMFResizable()" onmouseout="setMFUnresizable()"':''),(($resizable)?'cursor:e-resize':''));
  191.             else $output.='<div '.(($class)?'class="'.$class.'Header" ':' ').(($resizable)?' onmouseover="setMFResizable()" onmouseout="setMFUnresizable()" style="cursor:e-resize"':'').'>'.$header.'</div>';
  192.         }
  193.         $output.='<div id="'.$this->name.'" style="border:0px;padding:0px;height:100%"></div></div>';
  194.  
  195.         // Add treeView data
  196.         $output.=$this->createTreeView();
  197.  
  198.         // Add drag item if resizable
  199.         if($resizable) cfDragAddItem($this->HTMLDivID(),'+RESIZABLE+RESIZABLE_ONLY+FROZEN');
  200.  
  201.         return $output;
  202.     }
  203.  
  204.     /**
  205.      * @desc return treeView outer div id
  206.      *
  207.      * @return string id
  208.      */
  209.     function HTMLDivID(){
  210.         return $this->name.'_outer';
  211.     }
  212.  
  213.     /**
  214.      * @desc return JS item;
  215.      *
  216.      */
  217.     function JSItem(){
  218.         return 'treeViews["'.$this->name.'"]';
  219.     }
  220.  
  221.     /**
  222.      * @desc return JS code for unfolding a node
  223.      *
  224.      * @param string $completeFilename : bottom folder
  225.      */
  226.     function updateScript($completeFilename) {
  227.         $jsTree=$this->update($completeFilename,false,true);
  228.         if($this->sortReset)    return 'treeViews["'.$this->name.'"].reset ('.$jsTree.')';
  229.         else                     return 'treeViews["'.$this->name.'"].update('.$jsTree.',false)';
  230.     }
  231.  
  232.     /**
  233.      * @desc return JS code for selecting a node
  234.      *
  235.      * @param string $completeFilename : bottom folder
  236.      */
  237.     function updateAndSelectScript($completeFilename) {
  238.         $jsTree=$this->update($completeFilename,false,false);
  239.         if($this->sortReset)    return 'treeViews["'.$this->name.'"].reset ('.$jsTree.')';
  240.         else                     return 'treeViews["'.$this->name.'"].update('.$jsTree.',1)';
  241.     }
  242. }
  243.  
  244.  
  245.  
  246.  
  247. /**
  248.  * @desc Folder-dedicated treeView class
  249.  *
  250.  */
  251. class treeViewFolder extends treeView{
  252.  
  253.     /**
  254.      * @desc Update server-side folders tree, and generate JS code needed to update client-side tree
  255.      *
  256.      * PHP Tree structure:
  257.      * 'folder basename'=>Array(
  258.      *             (optional) 'ico'=>icon's name, or '' for standard folder icon,
  259.      *             'sub'=>array of subfolders trees, false if not processed, empty array if no subfolders
  260.      *             (optional) 'path'=>resource base path relative full pathname (only if top element)
  261.      *
  262.      * JS Tree structure:
  263.      * {"folder basename":{
  264.      *         (optional) "ico": icon's name or "" for standard folder icon,
  265.      *         "sub": subfolders tree, false if not processed, {} if no subfolders
  266.      *         },
  267.      * ...
  268.      * }
  269.      *
  270.      * @param string $bottomFolder: selected folder (real path, without *resourceBasePath*,
  271.      *             except for shared items type where topmost folder is *resourceBasePath*)
  272.      * @param boolean $resetTree: true to reset tree and return tree from base folder
  273.      * @return string: JS code or false if $folder not allowed
  274.      */
  275.     function update($bottomFolder=false, $resetTree=false, $unfoldBottomNode=true){
  276.         $dbg=false; $sortReset=false;
  277.  
  278.         if(!$resetTree) $phpTree=$this->phpTree; else $phpTree=false;
  279.  
  280.         // If sorting has changed, reset PHP tree
  281.         if($this->sortBy!=cfRGetVar('efSortBy') || $this->sortOrder!=cfRGetVar('efSortOrder')) {
  282.             $phpTree=false;
  283.             $this->sortBy=cfRGetVar('efSortBy');
  284.             $this->sortOrder=cfRGetVar('efSortOrder');
  285.             $sortReset=true;
  286.         }
  287.  
  288.         // Init tree
  289.         if(!$phpTree) {
  290.             $phpTree=array();
  291.             $treeBranch=&$phpTree;
  292.         }
  293.  
  294.         /**
  295.          * Init folders
  296.          */
  297.  
  298.         // $baseFolder: topmost tree folder (cfRGetVar('path') or '*resourceBasePath*')
  299.         if(cfSharedMode('list')) $baseFolder='*resourceBasePath*'; else $baseFolder=cfRGetVar('path');
  300.  
  301.         // $bottomFolder: lowest, seeked folder
  302.         if(!$bottomFolder) $bottomFolder=cfRGetVar('efCurrentDirectory');
  303.         if(cfSharedMode('list')) $bottomFolder=cfResourceRelativePath($bottomFolder); // shared list mode: convert back to relative path
  304.  
  305.         // $topFolder: folder from which tree will be returned, i.e. lowest tree folder including bottom folder,
  306.         // and already processed. Found by climbing up from bottomFolder
  307.         $topFolder=$bottomFolder;
  308.         if(substr($topFolder,-1)=='/') $topFolder=substr($topFolder,0,strlen($topFolder)-1); // Remove trailing /
  309.  
  310.         // treeView not initialized: set 'path' = baseFolder, and set topFolder to baseFolder
  311.         // Also reset if sorting has changed
  312.         if(!count($phpTree)) {
  313.             $phpTree=array('path'=>cfResourceRelativePath($baseFolder));
  314.             $topFolder=$baseFolder;
  315.         }
  316.         // Else, seek lowest processed folder matching with bottomFolder pattern
  317.         elseif($topFolder!='computerRoot' && $topFolder!='*resourceBasePath*'){
  318.             $treeBranch=&$phpTree;
  319.  
  320.             if($baseFolder=='computerRoot'){
  321.                 $donePath='';
  322.             }
  323.             else{
  324.                 $donePath=$baseFolder;
  325.                 if(substr($topFolder,0,strlen($baseFolder)+1)==$baseFolder.'/'){
  326.                     $topFolder=substr($topFolder,strlen($donePath)+1);
  327.                 }
  328.                 else $topFolder=$baseFolder;
  329.             }
  330.             if(cfSharedMode('list')) {
  331.                 //cfDbg('top:'.$topFolder.'    bottom:'.$bottomFolder.'    donePath:'.$donePath);
  332.                 //$topFolder=cfResourceRelativePath($topFolder);
  333.             }
  334.  
  335.             $tmpFolder=explode('/',$topFolder);
  336.             //cfDbg($tmpFolder);
  337.             //cfDbg($topFolder);
  338.             for ($i=0;$i<count($tmpFolder);$i++){
  339.                 if(!(isset($treeBranch['path']) && $tmpFolder[$i]==$treeBranch['path']) && !isset($treeBranch['sub'][$tmpFolder[$i]])){
  340.                     //cfDbg($i.')'.$tmpFolder[$i].' NOK');
  341.                     break;
  342.                 }
  343.                 //cfDbg($i.')'.$tmpFolder[$i]);
  344.                 if(isset($treeBranch['sub'][$tmpFolder[$i]])) $treeBranch=&$treeBranch['sub'][$tmpFolder[$i]];
  345.                 $donePath.='/'.$tmpFolder[$i];
  346.             }
  347.             if($donePath[0]=='/' && substr($donePath,0,2)!='//') $topFolder=substr($donePath,1); else $topFolder=$donePath;
  348.         }
  349.  
  350.         //else $topFolder='computerRoot';
  351.  
  352.         $processedFolder=$topFolder;
  353.         // Bottom folder
  354.         if(substr($bottomFolder,-1)=='/') $bottomFolder=substr($bottomFolder,0,strlen($bottomFolder)-1);
  355.  
  356.         //cfDbg($baseFolder.' - '.$topFolder.' - '.$bottomFolder,1);
  357.  
  358.         $processedFolder=$topFolder;
  359.         if($bottomFolder=='computerRoot')    $folderArray=array('computerRoot');
  360.         else{
  361.             if($topFolder=='computerRoot') $folderArray=array_merge(array('computerRoot'),explode('/',$bottomFolder));
  362.             else {
  363.                 if(strpos($topFolder,'/')===false) {
  364.                     $processedFolder='';
  365.                     $folderArray=explode('/',$bottomFolder);
  366.                 }
  367.                 else {
  368.                     $processedFolder=substr($topFolder,0,strrpos($topFolder,'/'));
  369.                     $folderArray=explode('/',substr($bottomFolder,strlen($processedFolder)+1));
  370.                 }
  371.             }
  372.         }
  373.  
  374.         $returnTree=array();
  375.         $processedTreeView=&$returnTree;
  376.  
  377.         // Selected directory
  378.         if(cfSharedMode('list')) $selDir=cfResourceRelativePath(cfRGetVar('efCurrentDirectory')); else $selDir=cfRGetVar('efCurrentDirectory');
  379.  
  380.         $level=0; $maxLevel=count($folderArray);
  381.         $sortByDate=(cfRGetVar('efSortBy')=='date');
  382.         foreach ($folderArray as $folderName) {
  383.             $level++;
  384.             $processedFolder=cfJoinPathFile($processedFolder,$folderName);
  385.  
  386.             // Uppercase drives paths
  387.             if(strlen($folderName)==2 && $folderName[1]==':') $folderName=strtoupper($folderName);
  388.             if(isset($processedTreeView['sub'][$folderName])) $processedTreeView=&$processedTreeView['sub'][$folderName];
  389.             elseif (isset($processedTreeView['sub']) && is_array($processedTreeView['sub'])){
  390.                 if($dbg) echo 'Failed on '.$folderName.' -------------<br>';
  391.                 if($dbg) cfVarDump($processedTreeView);
  392.                 return false;
  393.             }
  394.             if(!$unfoldBottomNode && $level==$maxLevel) $processedTreeView['bottom']='true';
  395.  
  396.             // Check files rights of processed folder
  397.             if(cfFileRights($processedFolder,'state')!='authorized') break;
  398.  
  399.             // shared list mode, *resourceBasePath*: list and sort dirs
  400.             if($processedFolder=='*resourceBasePath*'){
  401.                 $processedTreeView['ico']='../home.png';
  402.                 $processedTreeView['path']='*resourceBasePath*';
  403.                 $processedTreeView['label']=cfRGetVar('name');
  404.                 $dirs=array();
  405.  
  406.                 // Get shared directories
  407.                 foreach (cfSharedItems() as $cfn=>$type) if($type=='d' && cfFileRights($cfn,'state')=='authorized'){
  408.                     if($sortByDate)    $dirs[basename($cfn)]=@filemtime($cfn);
  409.                     else    $dirs[]=basename($cfn);
  410.                 }
  411.  
  412.                 // Sort them
  413.                 switch (cfRGetVar('efSortBy')){
  414.                     case 'name':
  415.                         natcasesort($dirs);
  416.                         if(cfRGetVar('efSortOrder')=='desc') $dirs=array_reverse($dirs,true);
  417.                         break;
  418.                     case 'date':
  419.                         if(cfRGetVar('efSortOrder')=='desc') arsort($dirs);
  420.                         else asort($dirs);
  421.                         foreach ($dirs as $n=>$time) $dirs[$n]=$n;
  422.                 }
  423.  
  424.                 foreach ($dirs as $dir)    {
  425.                     $processedTreeView['sub'][$dir]=array('sub'=>false);
  426.                     if(strpos($dir,':')) {
  427.                         $d=efDriveInfo($dir);
  428.                         $processedTreeView['sub'][$dir]['ico']=basename($d['icon']);
  429.                     }
  430.                 }
  431.             }
  432.             // Computer root : browse drives
  433.             elseif($processedFolder=='computerRoot'){
  434.                 $processedTreeView['ico']='computerRoot.png';
  435.                 $processedTreeView['path']='computerRoot';
  436.                 $processedTreeView['label']=cfCaption('explorerComputerRoot');
  437.                 // Browse drives, from a to z
  438.                 for ($i=66;$i<91;$i++) {
  439.                     $driveName=chr($i).":/";
  440.                     if (is_dir($driveName) && cfFileRights($driveName,'state')=='authorized'){
  441.                         $d=efDriveInfo($driveName);
  442.                         $processedTreeView['sub'][($driveName[0]).':']=array('sub'=>false,'ico'=>basename($d['icon']));
  443.                         $processedTreeView['sub'][($driveName[0]).':']['label']='('.$driveName.') '.cfUTF8Encode($d['volumeName']);
  444.                     }
  445.                 }
  446.             }
  447.             // Drive / Folder : browse subfolders
  448.             else{
  449.                 if($level==1 && strtolower($processedFolder)==strtolower(cfRGetVar('path'))) $processedTreeView['label']=cfUTF8Encode(cfRGetVar('name'));
  450.                 // Drive: set specific icon
  451.                 if(isset($folderName[1]) && $folderName[1]==':'){
  452.                     $d=efDriveInfo($processedFolder);
  453.                     $processedTreeView['ico']=basename($d['icon']);
  454.                     $processedTreeView['label']='('.$processedFolder.'/) '.cfUTF8Encode($d['volumeName']);
  455.                 }
  456.                 // List subfolders
  457.                 $processedTreeView['sub']=array();
  458.                 $dirs=array();
  459.  
  460.                 $realProcessedFolder=((cfSharedMode('list'))?cfSharedCompleteFilename($processedFolder):$processedFolder);
  461.  
  462.                 if($handle = @opendir($realProcessedFolder)){
  463.                     while (($file = @readdir($handle))!==false) {
  464.                         if(is_dir($dir=$realProcessedFolder.'/'.$file) && $file!='.' && $file!='..'
  465.                             && cfFileRights($dir,'state',false)=='authorized') {
  466.  
  467.                             if($sortByDate)    $dirs[basename($dir)]=filemtime($dir);
  468.                             else    $dirs[]=basename($dir);
  469.                         }
  470.                     }
  471.                 }
  472.                 // Sort them
  473.                 switch (cfRGetVar('efSortBy')){
  474.                     case 'name':
  475.                         natcasesort($dirs);
  476.                         if(cfRGetVar('efSortOrder')=='desc') $dirs=array_reverse($dirs,true);
  477.                         break;
  478.                     case 'date':
  479.                         if(cfRGetVar('efSortOrder')=='desc') arsort($dirs);
  480.                         else asort($dirs);
  481.                         foreach ($dirs as $n=>$time) $dirs[$n]=$n;
  482.                 }
  483.  
  484.                 foreach ($dirs as $dir)    $processedTreeView['sub'][basename($dir)]=array('sub'=>false);
  485.             }
  486.  
  487.             // Set as selected if current directory
  488.             if($processedFolder==$selDir) {
  489.                 $processedTreeView['selected']='true';
  490.                 $processedTreeView['unfolded']='true';
  491.             }
  492.         }
  493.  
  494.         // Set 'path' for topFolder
  495.         $treeBranch=$returnTree;
  496.  
  497.         // Update server-side treeview
  498.         $this->phpTree=$phpTree;
  499.         $this->save();
  500.  
  501.         $returnTree['path']=cfResourceRelativePath($topFolder);
  502.         //cfDbg($returnTree['sub']['C:'],1);
  503.  
  504.         // Inform
  505.         if($sortReset) $this->sortReset=true; else $this->sortReset=false;
  506.  
  507.         return $this->TVArrayToJS($returnTree,'');
  508.     }
  509.  
  510.  
  511.     /**
  512.      * @desc Return HTML code for tree view
  513.      *
  514.      * @param string $class
  515.      * @param mixed $resizable: false->not resizeable, 'h'->horizontaly resizeable, 'v'->verticaly resizeable
  516.      * @param boolean $closable
  517.      * @param string $extraStyle
  518.      * @param string $extraHTML
  519.      * @return string HTML code
  520.      */
  521.     function HTML($class=false, $resizable=false, $closable=false, $extraStyle=false, $extraHTML=false){
  522.         // Add common treeView JS
  523.         $output=$this->commonScripts();
  524.  
  525.         // Insert HTML stuff
  526.         $output.='<div id="'.$this->HTMLDivID().'"'.(($class)?' class="'.$class.'"':'').' style="margin:0;overflow:hidden;'.$extraStyle.'"'.(($extraHTML)?' '.$extraHTML:'').'>';
  527.         if(!cfTGetVar('avoidTitleBar')){
  528.             if($closable) $output.=outFrameHeaderTable((($class)?$class.'Header':''),outImage(outIcon('browse.png'),false,false,'vertical-align:middle;margin-right:0.5em').cfCaption('genDirectories'),outButtonSmall(false,'javascript:treeToggleFrame()',outIcon('close'),cfCaption('genClose')),(($resizable)?' onmouseover="setMFResizable()" onmouseout="setMFUnresizable()"':''),(($resizable)?'cursor:e-resize':''));
  529.             else $output.='<div '.(($class)?'class="'.$class.'Header" ':' ').(($resizable)?' onmouseover="setMFResizable()" onmouseout="setMFUnresizable()" style="cursor:e-resize"':'').'>'.outImage(outIcon('browse.png'),false,false,'vertical-align:middle;margin-right:0.5em').cfCaption('genDirectories').'</div>';
  530.  
  531.         }
  532.         $output.='<div id="'.$this->name.'" style="overflow:auto;border:0px;padding:0px;height:100%'.((cfGetBrowser()=='ie')?';width:95%':'').'"></div></div>'; // Note: width must be set under IE for overflow to work
  533.  
  534.         // Add dblClick function
  535.         //$this->dblClickFunction='treeFolderDblClickSelect';
  536.  
  537.         // Add treeView data
  538.         $output.=$this->createTreeView();
  539.  
  540.         // Add drag item if resizable
  541.         if($resizable) cfDragAddItem($this->HTMLDivID(),'+RESIZABLE+RESIZABLE_ONLY+FROZEN');
  542.  
  543.         return $output;
  544.     }
  545. }
  546.  
  547.  
  548.  
  549.  
  550. /**
  551.  * @desc load tree from session data or create a new one if inexistant
  552.  *
  553.  * @param string $name tree name
  554.  * @return treeView object
  555.  */
  556. function treeFolderLoad($name){
  557.     if(cfRGetVar('treeView_'.$name)) return cfRGetVar('treeView_'.$name);
  558.     else return new treeViewFolder($name);
  559. }
  560. ?>